package com.auth.manager.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @version 1.0.0
 * @Date: 2022/5/8 20:22
 * @Author ZhuYouBin
 * @Description 前后端分离模式下,CORS跨域解决
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {

    private static final String[] HTTP_METHODS = new String[]{
            "GET", "POST", "PUT", "DELETE"
    };

    // 这个方法用于配置哪些请求可以支持CORS跨域访问
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOriginPatterns("*")
                .allowedMethods(HTTP_METHODS)
                .allowCredentials(true)
                .allowedHeaders("*")
                .maxAge(3600);
    }

}
